import http from "../utils/request";
import { baseURL } from "../utils/base_url";
import { getStorage, showTost } from "../utils/common";

interface DefaultRes {

}

// 省市区
export function baseListByParent(id: string): Promise<any> {
  return http("/api/biz/area/baseListByParent/" + id);
}

export function baseListByType(type: string): Promise<any> {
  return http("/api/biz/area/baseListByType/" + type);
}
export function getAd(type: string): Promise<any> {
  return http("/api/ad/getAd/" + type);
}

export function getProductList(params: any): Promise<any> {
  return http("/api/mall/product/list", params, "POST");
}

// 获取商品分类列表
export function getCategoryList(params: any): Promise<any> {
  return http("/api/mall/category/list", params, "POST");
}

export function getArticleList(params: any): Promise<any> {
  return http("/api/article/articleList", params, "POST");
}

export function getArticleDetail(id: string): Promise<any> {
  return http("/api/article/detail/" + id);
}

// 修改用户信息

export function editUserInfo(params: any): Promise<any> {
  return http("/api/user/edit", params, "POST");
}

// 获取用户信息
export function getUserByBusinessId(businessId: string): Promise<any> {
  return http("/api/user/getUserByBusinessId/" + businessId);
}

// 修改渠道推荐人
export function editChannelRecommend(params: any): Promise<any> {
  return http("/api/user/editChannelRecommend", params, "POST");
}

// 获取商品详情
export function getProductDetail(id: string): Promise<any> {
  return http("/api/mall/product/detail/" + id);
}

// 检查密码
export function checkPwd(params: any): Promise<any> {
  return http("/api/user/checkPwd", params, "POST");
}

// 创建商城订单
export function createMallOrder(params: any): Promise<any> {
  return http("/api/mall/order/createMallOrder", params, "POST");
}


// 获取商城订单列表
export function getMallOrderList(params: any): Promise<any> {
  return http("/api/mall/order/list", params, "POST");
}


// 获取用户统计信息
export function getUserStatisticsVo(): Promise<any> {
  return http("/api/user/getUserStatisticsVo");
}


// 获取团队列表
export function getTeamUsers(params: any): Promise<any> {
  return http("/api/user/getTeamUsers", params, "POST");
}

// 获取用户收益统计
export function getUserIncomeStatistics(params: any): Promise<any> {
  return http("/api/user/getUserIncomeStatistics", params, "POST");
}


// 获取用户账户变动列表
export function getAccountChangeList(params: any): Promise<any> {
  return http("/api/user/getAccountChangeList", params, "POST");
}


// 获取用户账户变动列表
export function getFoundation(): Promise<any> {
  return http("/api/index/getFoundation");
}

// 获取商品分类列表
export function getProductCategoryList(params: any): Promise<any> {
  return http("/api/mall/product/list", params, "POST");
}

// 获取验证码
export function getTransferSmsCode(): Promise<any> {
  return http("/api/user/getTransferSmsCode");
}

// 获取邮箱验证码
export function sendEmailCodeByCaptcha(params: any): Promise<any> {
  return http("/api/sms/sendEmailCodeByCaptcha", params, "POST");
}

// 重置密码获取验证码
export function sendSmsCodeByCaptcha(params: any): Promise<any> {
  return http("/api/sms/sendSmsCodeByCaptcha", params, "POST");
}

// 重置密码
export function resetPwd(params: any): Promise<any> {
  return http("/api/user/unAuth/resetPwd", params, "POST");
}

// 邮箱注册
export function registerEmail(params: any): Promise<any> {
  return http("/api/login/registerEmail", params, "POST");
}
// 手机注册
export function registerPhone(params: any): Promise<any> {
  return http("/api/login/register", params, "POST");
}



// 登录
export function loginIn(params : any) : Promise<any> {
	return http('/api/login/loginIn', params, 'POST')
}

















// 创建转账订单
export function createTransferOrder(params: any): Promise<any> {
  return http("/api/user/createTransferOrder", params, "POST");
}
// 创建转账团队订单
export function createTeamTransferOrder(params: any): Promise<any> {
  return http("/api/user/createTeamTransferOrder", params, "POST");
}

// 兑换商城订单
export function createExchangeOrder(params: any): Promise<any> {
  return http("/api/user/createExchangeOrder", params, "POST");
}


//  获取转账订单列表
export function exchangeOrderList(params: any): Promise<any> {
  return http("/api/user/exchangeOrderList", params, "POST");
}


//  获取转账订单列表
export function getApiCashOrderList(params: any): Promise<any> {
  return http("/api/user/cash/getApiCashOrderList", params, "POST");
}




//  获取银行卡列表
export function getApiUserCardList(): Promise<any> {
  return http("/api/user/card/getApiUserCardList");
}
 // 添加提现订单
export function addCashOrder(params: any): Promise<any> {
  return http("/api/user/cash/addCashOrder", params, "POST");
}
// 获取配置信息
export function getConfigByKey(key: string): Promise<any> {
  return http("/api/config/getConfigByKey/sys.app.notice?key=" + key);
}

// 删除提现方式
export function deleteCard(id: string): Promise<any> {
  return http("/api/user/card/delete/"+id, {} ,"DELETE");
}

// 添加提现方式
export function addUserCard(params: any): Promise<any> {
  return http("/api/user/card/addUserCard", params, "POST");
}
// 修改提现方式
export function editUserCard(params: any): Promise<any> {
	return http('/api/user/card/modifyUserCard', params, 'POST') as any
}



export function upload(params: any): Promise<any> {
  return new Promise((resolve, reject) => {
    uni.showLoading({
      title: "上传中...",
    });
    uni.uploadFile({
      url: baseURL + "/api/file/upload",
      filePath: params,
      name: "file",
      header: {
        token: getStorage("token"),
        Authorization: getStorage("token"),
      },
      success: (res: any) => {
        resolve(JSON.parse(res.data));
      },
      fail: (err) => {
        reject(err);
      },
      complete: () => {
        uni.hideLoading();
      },
    });
  });
}



























// 查绑定车牌号
export function bindVno(params : {
	"userId" : string,
	"vno" : string,
	"userName" ?: string,

}) : Promise<DefaultRes> {
	return http('/api/auth/mer/store/bindVno', params, 'POST') as any
}
// 查询机票链接
export function getFlightUrl() : Promise<DefaultRes> {
	return http('/api/auth/user/center/menu/getFlightUrl') as any
}

// 获取客服服务信息
export function getMenuList(params : { type? : '1' | '2' , id?: string}) : Promise<any> {
	return http('/api/auth/user/center/menu/getMenuList', params) as any
}

// 获取客服服务信息
export function getServiceInfo() : Promise<any> {
	return http('/api/auth/customer/service/getServiceInfo') as any
}

// 注册短信获取验证码
export function getSmsCodeByRegister(params : { mobile : string }) : Promise<DefaultRes> {
	const currentDate = new Date();
	currentDate.setDate(currentDate.getDate() - 1);
	params['verifyCode'] = currentDate.getTime();
	return http('/api/unAuth/user/getSmsCodeByRegister', params) as any
}

// 忘记密码获取短信验证码
export function getSmsCodeByForgot(params : { mobile : string }) : Promise<DefaultRes> {
	const currentDate = new Date();
	currentDate.setDate(currentDate.getDate() - 1);
	params['verifyCode'] = currentDate.getTime();
	return http('/api/unAuth/user/getSmsCodeByForgot', params) as any
}
// 注销获取短信验证码
export function getSmsCodeForLogout(params : { mobile : string }) : Promise<DefaultRes> {
	const currentDate = new Date();
	currentDate.setDate(currentDate.getDate() - 1);
	params['verifyCode'] = currentDate.getTime();
	return http('/api/auth/user/getSmsCodeForLogout', params) as any
}
// 企业商户获取通联绑定手机号验证码
export function getMerCompanyTlSmsCodeForBind(params : { mobile : string }) : Promise<DefaultRes> {
	return http('/api/auth/allinPay/getMerCompanyTlSmsCodeForBind', params) as any
}


// 绑定微信获取验证码
export function getSmsCodeForBindWx(params : { mobile : string }) : Promise<DefaultRes> {
	const currentDate = new Date();
	currentDate.setDate(currentDate.getDate() - 1);
	params['verifyCode'] = currentDate.getTime();
	return http('/api/unAuth/user/getSmsCodeForBindWx', params) as any
}
// 微信-用户解绑
export function wxUnBinding() : Promise<DefaultRes> {
	return http('/api/auth/user/userInfo/wxUnBinding', '', 'POST') as any
}


// 用户忘记密码接口
export function forgotPwd(params : {
	mobile : string,
	password : string,
	smsCode : number,
}) : Promise<DefaultRes> {
	return http('/api/unAuth/user/forgotPwd', params, 'POST') as any
}

// 微信-用户绑定
export function appWxBinding(params : { mobile ?: string, openid : string, smsCode ?: number }) : Promise<DefaultRes> {
	return http('/api/unAuth/login/appWxBinding', params, 'POST') as any
}

// 获取协议书
export function getAgreement(params : { agreementId : string }) : Promise<any> {
	return http('/api/unAuth/sys/agreement/getAgreement', params) as any
}

// 赠送会员配置列表
export function getRechargeProportionApiList() : Promise<any> {
	return http('/api/auth/recharge/proportion/getRechargeProportionApiList',)
}
// 会员赠送列表
export function getGivingList(params : any) : Promise<any> {
	return http('/api/auth/user/rechangeOrder/getGivingList', params, 'POST') as any
}
// 商户--门店数据统计明细
export function getStoreMainStatisticsDetail(params : { tabType : number, startDateStr ?: string, endDateStr ?: string }) : Promise<any> {
	return http('/api/auth/mer/manage/storeReport', params, 'POST') as any
}

interface GetDictListByTypeRes {
	code : number;
	data : {
		dictId : string;
		label : string;
		type : string;
		value : string;
	}[];
	msg : string;
}
// 字典表信息
export function getByType(params : { type : string }) : Promise<GetDictListByTypeRes> {
	return http('/api/auth/sys/dict/getByType', params) as any
}


// 公告模块
export function getNoticeById(params : { id : string }) : Promise<any> {
	return http('/api/auth/notice/getNoticeById', params)
}
// 公告列表
export function getApiList(params : any) : Promise<any> {
	return http('/api/auth/notice/getApiList', params, 'POST')
}

// 首页banner
export function getHomeBanner() : Promise<any> {
	return http('/api/unAuth/index/getIndexBanner')
}

// 首页业务类别
export function getIndexBusinessTypes() : Promise<any> {
	return http('/api/unAuth/index/getIndexBusinessTypes')
}
// 本地业务类别
export function getIndexLifeBusinessTypes() : Promise<any> {
	return http('/api/unAuth/index/getIndexLifeBusinessTypes')
}
// 首页联营门店列表

export function getIndexJoinedStoreList(params : {
	"latitude" ?: string,
	"longitude" ?: string,
	"tyjPageNum" : number,
	"tyjPageSize" : number
}) : Promise<{
	code : number;
	msg : string;
	pageNum : number;
	pageSize : number;
	rows : {
		address : string;
		city : string;
		distance : number;
		doorPhotoUrl : string;
		province : string;
		storeId : string;
		storeName : string;
	}[];
	total : number;
}> {
	return http('/api/unAuth/mer/store/getIndexJoinedStoreList', params, 'POST') as any
}


// 首页滚动信息
export function getIndexRollingInfo() : Promise<any> {
	return http('/api/unAuth/index/getIndexRollingInfo')
}
// 通过级别查询列表
export function getAreaByLevel(params : { level : string | number }) : Promise<any> {
	return http('/api/auth/area/getAreaByLevel', params)
}
// 通过父节点查询列表
export function getAreaByParentId(params : { parentId : string }) : Promise<any> {
	return http('/api/auth/area/getAreaByParentId', params)
}
/** 
 * 通过车牌号查询客户详情
 * @param {object} params req
 * @param {string} params.id 客户ID
 * @param {string} params.userId 系统用户ID
 * @param {string} params.vno 车牌号vno
 * @returns
 */
interface GetDetailByVnoRes {
	code : number;
	data : {
		createTime : Record<string, unknown>;
		customerType : number;
		id : string;
		merId : string;
		mobile : string;
		sex : string;
		updateTime : Record<string, unknown>;
		userId : string;
		userName : string;
		vno : string;
	};
	msg : string;
}

export function detailByVno(params : {
	"id" ?: string,
	"userId" ?: string,
	"vno" : string
}) : Promise<GetDetailByVnoRes> {
	return http('/api/auth/mer/customer/detailByVno', params, 'POST') as any
}


// 添加收货地址
export function addAddress(params : any) {
	return http('/api/user/addAddress', params, 'POST')
}

// 删除收货地址
export function deleteAddress(params : { addrId : string }) {
	return http('/api/auth/address/delete', params, 'DELETE')
}
// 获取收货地址列表
export function getApiListAddress() : Promise<any> {
	return http('/api/auth/address/getApiListAddress')
}
// 获取收货地址列表
export function getDetailAddress(params : { addrId : string }) : Promise<any> {
	return http('/api/auth/address/getDetail', params)
}


// 修改收货地址
export function modifyAddress(params : any) {
	return http('/api/auth/address/modifyAddress', params, 'POST')
}
// 检查经纬度
export function checkUserLnglat() {
	return http('/api/auth/user/checkUserLnglat')
}

// 粉丝成长---粉丝列表
export function getFansList(params : any) : Promise<any> {
	return http('/api/auth/user/getFansList', params, 'POST')
}

// 粉丝成长---头部信息

export function getFansPageInfo() : Promise<any> {
	return http('/api/auth/user/getFansPageInfo')
}

// 获取邀请好友-个人推荐页面信息
export function getInvitationInfo() {
	return http('/api/auth/user/getInvitationInfo')
}

// 采集用户当前经纬度信息，获取地理信息
export function userCoordinates(params : { latitude ?: string, longitude ?: string; }) : Promise<DefaultRes> {
	return http('/api/auth/user/userInfo/userCoordinates', params, 'POST') as any
}

// 获取分享图片
export function getMinProgramCode(invitation : string) : string {
	return baseURL + '/api/unAuth/user/getMinProgramCode?invitation=' + invitation
}

// 是否展示微信登录
export function getWxLoginOpenStatus() : Promise<DefaultRes> {
	return http('/api/unAuth/login/getWxLoginOpenStatus', { dictId: '20001001' }) as any
}
// 商户--门店数据月度对比
export function getStoreMainStatisticsMonthDetail(params : { monthStr : string, orderType : string }) : Promise<any> {
	return http('/api/auth/mer/store/getStoreMainStatisticsMonthDetail', params) as any
}
// 员工邀请反馈
export function submitInvite(params : { entryStatus : number }) : Promise<DefaultRes> {
	return http('/api/auth/user/submitInvite', params, 'POST') as any
}

// 核销员解绑
export function unbind() : Promise<DefaultRes> {
	return http('/api/auth/mer/clerk/unbind', {}, 'POST') as any
}



/** 
 * 经营报表
 * @param {object} params 经营报表请求参数
 * @param {number} params.dataType tab类型【0:全部，1:平台，2：开单】
 * @param {string} params.dateStr 时间字符串
 * @returns
 */

interface GetReportDataRes {
	code : number;
	data : {
		merManageReportChainRatioVos : {
			amount : number;
			month : string;
		}[];
		merManageReportChannelVo : {
			merManageReportChannelDetailVos : {
				channelId : string;
				channelName : string;
				orderCount : number;
				orderTotalAmount : number;
				percent : number;
			}[];
			orderCount : number;
			orderTotalAmount : number;
		};
		merManageReportOrderVo : {
			merManageReportOrderDetailVos : {
				businessType : string;
				businessTypeLabel : string;
				orderCount : number;
				orderTotalAmount : number;
				percent : number;
			}[];
			orderCount : number;
			orderTotalAmount : number;
		};
	};
	msg : string;
}
export function manageReport(params : { dataType : number, dateStr : string }) : Promise<GetReportDataRes> {
	return http('/api/auth/mer/manage/report', params, 'POST') as any
}

// 根据邀请码获取门店
export function getMerStoreIdByInvitation(params : { invitation : string }) : Promise<{
	code : number;
	data : string;
	msg : string;
}> {
	return http('/api/unAuth/user/getMerStoreIdByInvitation', params) as any
}

// 首页收款业务类别
export function getIndexReceiveBusinessTypes() : Promise<{
	code : number;
	data : {
		sort : number;
		typeCode : string;
		typeName : string;
	}[];
	msg : string;
}> {
	return http('/api/unAuth/index/getIndexReceiveBusinessTypes') as any
}


//人保积分查询
export function getPiccPoints() : Promise<any> {
	return http('/api/auth/picc/getPoints')
}

//人保积分领取
export function grantPiccPoints(params) : Promise<any> {
	return http('/api/auth/picc/grantPoints', params, 'POST') as any
}

//人保积分提现
export function cashPoints(params) : Promise<any> {
	return http('/api/auth/picc/cashPoints', params, 'POST') as any
}

//人保积分变动明细
export function getPointChanges(params) : Promise<any> {
	return http('/api/auth/picc/getPointChanges', params, 'POST') as any
}

// 获取app版本信息
export function getAppVersion(): Promise<any> {
  return http("/api/app/version/getVersionNew");
}

// 申请渠道
export function applyChannel(params: any): Promise<any> {
  return http("/api/channel/applyChannel", params, "POST");
}

// 获取申请渠道详情
export function getApplyDetail(): Promise<any> {
  return http("/api/channel/getApplyDetail");
}

// 修改申请渠道
export function editApplyChannel(params: any): Promise<any> {
  return http("/api/channel/editApplyChannel", params, "POST");
}


// 获取区域设备总数
export function getChannelDeviceCount(params: any): Promise<any> {
  return http("/api/channel/getChannelDeviceCount", params, "POST");
}



// 获取用户账户信息
export function getUserAccountVo(): Promise<any> {
  return http("/api/user/getUserAccountVo");
}

// 获取用户渠道信息
export function getUserChannelVo(): Promise<any> {
  return http("/api/user/getUserChannelVo");
}